package com.md.client;

import com.md.api.OauthApi;
import com.md.client.helper.DefaultOauthApiController;
import com.md.request.ReplacementTokenRequest;
import com.md.response.ReplacementTokenResponse;
import com.md.util.SpringContextUtil;
import lombok.experimental.UtilityClass;

/**
 * @author 刘骄阳
 * 2024-07-14 22:37
 */
@UtilityClass
public class OpenOauthClient {

  private OauthApi oauthApi;

  private static OauthApi getOpenSystemApi() {
    if (oauthApi == null) {
      oauthApi = SpringContextUtil.getBean(DefaultOauthApiController.class);
    }
    return oauthApi;
  }

  public static ReplacementTokenResponse replacement(final String shortToken) {
    ReplacementTokenRequest request = new ReplacementTokenRequest();
    request.setShortToken(shortToken);
    return getOpenSystemApi().replacement(request).getData();
  }

}
